#pragma once

// Definition for a binary tree node.
struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

namespace common
{
	TreeNode* listToTree(std::vector<string> strList)
	{
		TreeNode* root;
		TreeNode* result = nullptr;
		std::queue<TreeNode*> queue;
		for (size_t i = 0; i < strList.size(); i++) {
			if (i == 0) {
				root = new TreeNode(atoi(strList[i].c_str()));
				result = root;
				queue.push(root);
			}
			if (!queue.empty()) {
				root = queue.front();
				queue.pop();
			}
			else {
				break;
			}
			if (i + 1 < strList.size() && strList[i + 1] != "null") {
				root->left = new TreeNode(atoi(strList[i + 1].c_str()));
				queue.push(root->left);
			}
			if (i + 2 < strList.size() && strList[i + 2] != "null") {
				root->right = new TreeNode(atoi(strList[i + 2].c_str()));
				queue.push(root->right);
			}
			i = i + 1;
		}
		return result;

	}



}